home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / cat_exe.zip / LIFE_2.CAR < prev    next >
Text File  |  1994-11-18  |  2KB  |  83 lines

  1. (* enhanced version of Conveys LIFE program *)
  2. (* cells just died or just born are represented with particular colors
  3.    via bit manipulation.  *)
  4.  
  5. RECIPE  XYSize  =  60;
  6.         Zet     =  4;
  7.         Colors  =  4;
  8.  
  9. CONST dead      = %00; (* bit sample 0000 *)
  10.       just_died = %01; (* bit sample 0001 *)
  11.       just_born = %10; (* bit sample 0010 *)
  12.       alive     = %11; (* bit sample 0011 *)
  13.               (*                       A  *)
  14.               (*                       |  *)
  15.               (*              "alive bit" *)
  16.  
  17. REF   east    [1,0];
  18.       west      [-1,0];
  19.       north     [0,-1];
  20.       south     [0,1];
  21.       north_ea    [1,-1];
  22.       north_we  [-1,-1];
  23.       south_ea  [1,1];
  24.       south_we  [-1,1];
  25.  
  26. VAR  a;
  27.  
  28.  
  29. PROC add_second_bit:;    (* procedure evaluates second bit of   *)
  30.                          (* neighbors that indicate alive state *)
  31. BEGIN                    (* and returns sum of found bits       *)
  32. RETURN ((east XOR %01) SHR 1) + ((west XOR %01) SHR 1) +
  33.        ((north XOR %01) SHR 1)   + ((south XOR %01) SHR 1) +
  34.        ((north_ea XOR %01) SHR 1) + ((north_we XOR %01) SHR 1) +
  35.        ((south_ea XOR %01) SHR 1)   + ((south_we XOR %01) SHR 1)
  36. END add_second_bit;
  37.  
  38. EVENT SetUp;
  39.       TubeForm;
  40.       PlClipActive;
  41.  
  42. EVENT E0;
  43.       RGBBrush (dead, 0, 0, 0);          (* black *)
  44.       RGBBrush (just_died, 152, 88, 46); (* brown *)
  45.       RGBBrush (just_born, 74, 229, 3);  (* light green *)
  46.       RGBBrush (alive, 50, 174, 30);     (* dark green *)
  47.  
  48. EVENT E1; (* initialization a *)
  49.      PARALLEL DO
  50.      a := Random (500);
  51.      IF a > 492
  52.        THEN Self := alive
  53.        ELSE Self := dead
  54.      FI;
  55.      OD;
  56.      ShowPlane;
  57.  
  58.  
  59. EVENT E2; (* initialization b *)
  60.    PlFillRandom (dead, alive);
  61.    ShowPlane;
  62.  
  63.  
  64. EVENT E3;
  65. PARALLEL DO
  66. a := add_second_bit;
  67.  
  68. IF (a = 2) OR (a = 3)
  69.   THEN IF (a = 3) AND ((Self = dead) OR (Self = just_died))
  70.        THEN Self := just_born;
  71.        ELSE Self := alive;
  72.        FI;
  73.   ELSE IF (Self = alive) OR (Self = just_born)
  74.        THEN Self := just_died;
  75.        ELSE Self := dead;
  76.        FI;
  77. FI;
  78. OD;
  79. ShowPlane;
  80.  
  81. END.
  82.  
  83.